var hiprintTemplate;
$(document).ready(function () {
   var customPrintJson = {"panels":[{"index":0,"height":60,"width":80,"paperHeader":0,"paperFooter":129,"printElements":[{"tid":"testModule.tableCustom","options":{"left":6,"top":9,"height":36,"width":207,"autoCompletion":true,"field":"table_printDatast","textAlign":"center","columns":[[{"title":"姓名","field":"姓名","width":53.25,"colspan":1,"rowspan":1,"checked":true,"columnId":"姓名","tableColumnHeight":30,"tableTextType":"text","tableBarcodeMode":"CODE128A"},{"title":"销售金额","field":"销售金额","width":53.25,"colspan":1,"rowspan":1,"checked":true,"columnId":"销售金额","tableColumnHeight":30,"tableTextType":"qrcode","tableBarcodeMode":"CODE128A"}]]}}],"paperNumberLeft":196,"paperNumberTop":148,"paperNumberFormat":"paperNo-paperCount"}]}
    //初始化打印插件
    hiprint.init({ providers: [new customElementTypeProvider()] });

    //hiprint.PrintElementTypeManager.build('.hiprintEpContainer', 'testModule');
    //设置左侧拖拽事件
    hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'));

    hiprintTemplate = new hiprint.PrintTemplate({
        template: customPrintJson,
        settingContainer: '#PrintElementOptionSetting',
        paginationContainer: '.hiprint-printPagination'
    });
    //打印设计
    hiprintTemplate.design('#hiprint-printTemplate');

    var userAgent = navigator.userAgent;// 取得浏览器的userAgent字符串

    var isWebKit =  navigator.userAgent.indexOf('WebKit') > -1  // 是否是WebKit 内核 
    console.log('谷歌内核'+ isWebKit)  // 返回 true  则是，false  则不是

    var isChrome =  navigator.userAgent.indexOf('Chrome') > -1  // 是否是谷歌 
    console.log('谷歌'+ isChrome)  // 返回 true  则是 ，false  则不是

    var isFirefox =  navigator.userAgent.indexOf('Firefox') > -1  // 是否是火狐  ，火狐内核Gecko 
    console.log('火狐'+ isFirefox)  // 返回 true  则是 ，false  则不是

    if (isWebKit == false) {
    	layer.msg('建议您使用谷歌浏览器！', {icon: 5});
    }

    if (isFirefox == true) {
    	layer.msg('建议您使用【谷歌浏览器】！<br><br>当前使用的【火狐浏览器】可能出现问题：<br>1.因转置问题可能出现内容偏移！<br>2.暂时无法打印预览！', {icon: 5});
    }
});
var setPaper = function(paperTypeOrWidth, height) {
    hiprintTemplate.setPaper(paperTypeOrWidth, height)
}
//居中事件
function setElsAlign(e) {
  hiprintTemplate.setElsAlign(e)
}

var clearTemplate = function() {
    layer.alert('确定要清空面板数据么?', {
        icon: 3,
        title: '谨慎操作[不可逆]',
        btn: ['确认', '取消']
    }, function(index) {
        hiprintTemplate.clear();
        layer.closeAll()
    })
}
var rotatePaper = function() {
    hiprintTemplate.rotatePaper()
}
var getJsonTid = function() {
    $('#textarea').html(JSON.stringify(hiprintTemplate.getJsonTid()));
	var getJsonTid_json = JSON.parse($('#textarea').val());
	
	var obj = getJsonTid_json.panels[0].printElements;
	
	//console.log($('#textarea').val());
	
	for (var i = 0; i < obj.length; i++) {
	    for (key in obj[i]) {
	        //console.log(key + "=" + obj[i][key]);
			if(obj[i][key]=="testModule.tableCustom"){//表格添加ID
				//console.log(obj[i]["options"].columns[0]);
				var obj_j = obj[i]["options"].columns[0];
				for (var ii = 0; ii < obj_j.length; ii++) {
				    for (keys in obj_j[ii]) {
				        //console.log(ii + "title: " + obj_j[ii]["title"]);
						var getJsonTid_json_gg = getJsonTid_json;
						getJsonTid_json_gg.panels[0].printElements[i]["options"].columns[0][ii]["field"] = obj_j[ii]["title"];
						getJsonTid_json_gg.panels[0].printElements[i]["options"].columns[0][ii]["columnId"] = obj_j[ii]["title"];
						//console.log(getJsonTid_json_gg);
						$('#textarea').html(JSON.stringify(getJsonTid_json_gg));
				    }
				}
			}else if(obj[i][key]=="testModule.qrcodetable"){//二维码表格添加ID
				//console.log(obj[i]["options"].columns[0]);
				var obj_j = obj[i]["options"].columns[0];
				for (var ii = 0; ii < obj_j.length; ii++) {
				    for (keys in obj_j[ii]) {
				        //console.log(ii + "title: " + obj_j[ii]["title"]);
						var getJsonTid_json_gg = getJsonTid_json;
						getJsonTid_json_gg.panels[0].printElements[i]["options"].columns[0][ii]["field"] = obj_j[ii]["title"];
						getJsonTid_json_gg.panels[0].printElements[i]["options"].columns[0][ii]["columnId"] = obj_j[ii]["title"];
						getJsonTid_json_gg.panels[0].printElements[i]["options"].columns[0][ii]["tableTextType"] = "qrcode";
						//console.log(getJsonTid_json_gg);
						$('#textarea').html(JSON.stringify(getJsonTid_json_gg));
				    }
				}
			}else if(obj[i][key]=="testModule.barcodetable"){//条形码表格添加ID
				//console.log(obj[i]["options"].columns[0]);
				var obj_j = obj[i]["options"].columns[0];
				for (var ii = 0; ii < obj_j.length; ii++) {
				    for (keys in obj_j[ii]) {
				        //console.log(ii + "title: " + obj_j[ii]["title"]);
						var getJsonTid_json_gg = getJsonTid_json;
						getJsonTid_json_gg.panels[0].printElements[i]["options"].columns[0][ii]["field"] = obj_j[ii]["title"];
						getJsonTid_json_gg.panels[0].printElements[i]["options"].columns[0][ii]["columnId"] = obj_j[ii]["title"];
						getJsonTid_json_gg.panels[0].printElements[i]["options"].columns[0][ii]["tableTextType"] = "barcode";
						getJsonTid_json_gg.panels[0].printElements[i]["options"].columns[0][ii]["hideTitle"] = false;
						//console.log(getJsonTid_json_gg);
						$('#textarea').html(JSON.stringify(getJsonTid_json_gg));
				    }
				}
			}
	    }
	}
}
var directPrint = function() {
    getJsonTid();
    hiprintTemplate.print()
}
var directPrint_2 = function() {
    getJsonTid();
    var hiprintTemplate = new hiprint.PrintTemplate({
        template: JSON.parse($('#textarea').val())
    });
    var printData = document.getElementById('printDatas').value;
    if (!printData) {
        layer.msg('请先上传正确的数据表！', {icon: 1});
    }else{
        hiprintTemplate.print(JSON.parse(printData),{paperNumberToggleInEven:true});
    }
};
var Printpdf = function() {
    getJsonTid();
    var printData = document.getElementById('textarea').value;
    //scale 越大 pdf 越清晰，文件越大  默认2,建议谷歌浏览器使用
    hiprintTemplate.toPdf(printData, 'Jmw_在线标签设计打印_导出_PDF_' + new Date().toLocaleString(),{scale:3 });
    $('#print_perview').modal('hide');
    layer.msg('提交处理完毕<br>请稍后查看下载页面数据！', {icon: 0});
}
var Printpdf_2 = function() {
    getJsonTid();
    var hiprintTemplate = new hiprint.PrintTemplate({
        template: JSON.parse($('#textarea').val())
    });
    var printData = document.getElementById('printDatas').value;
    if (!printData) {
        layer.msg('请先上传正确的数据表！', {icon: 1});
    }else{
    //console.log(JSON.parse(printData));
        hiprintTemplate.toPdf(JSON.parse(printData), 'Jmw_在线标签设计打印_批量导出_PDF_' + new Date().toLocaleString(),{scale:3 ,paperNumberToggleInEven:true});
        $('#print_perview').modal('hide');
        layer.msg('提交处理完毕<br>请稍后查看下载页面数据！', {icon: 0});
    }
}
var print_perview_1 = function() {
    layer.msg('出现空白时请注意检查内容<br>单条打印时请删除字段名！<br><br><span style="color:red;">黑色框线为设置纸张预览边界<br>打印时不会打印出来</span>', {icon: 1});
    $("#yrdy1").show();
    $("#yrdy2").hide();
    $("#dc_pdf1").show();
    $("#dc_pdf2").hide();
    getJsonTid();
    var printData = document.getElementById('textarea').value;
    $('#print_perview .modal-body .prevViewDiv').html(hiprintTemplate.getHtml(printData));
    $('#print_perview').modal('show');
};
var print_perview_2 = function() {
    layer.msg('出现空白时请注意:<br><br>1.检查字段是否设置正确<br>2.数据是否导入正常！<br><br><span style="color:red;">黑色框线为设置纸张预览边界<br>打印时不会打印出来</span>', {icon: 1});
    $("#yrdy2").show();
    $("#yrdy1").hide();
    $("#dc_pdf2").show();
    $("#dc_pdf1").hide();
    getJsonTid();
    var printData = document.getElementById('textarea').value;
    var hiprintTemplate = new hiprint.PrintTemplate({
        template: JSON.parse($('#textarea').val())
    });
    var printData = document.getElementById('printDatas').value;
    $('#print_perview .modal-body .prevViewDiv').html(hiprintTemplate.getHtml(JSON.parse(printData)),{paperNumberToggleInEven:true});
    $('#print_perview').modal('show');
};
$(document).ready(function() {
    $('[data-toggle="tooltip"]').tooltip();
    var user = $.cookie('user');
    if (user != null) {
        $("#userup").html("登出");
        $("#userid").html(user);
        document.getElementById("modbut").style.display = "inline";
        getmod();
    }
});

function getFile(source) {
    if(window.FileReader) {
        var oFileReader = new FileReader(),
            oFile = source.files[0],
            oBase64 = document.getElementById("base64"),
            oPreview = document.getElementById("preview");
        // 过滤非图片文件
        if(/^image*/.test(oFile.type)) {
            oFileReader.onloadend = function(e) {
                oBase64.innerHTML = "转化完毕,关闭本页面点击确认按钮加载";
                $('#img_src').val(e.target.result);
                oPreview.src = e.target.result;
                $("#img_f").val("");
                setTimeout("layer.msg('转化完毕,点击确认按钮加载！', {icon: 0});", 1000 );
                $('#img_div').modal('hide');
            };
            // 将图片转为base64格式
            oFileReader.readAsDataURL(oFile);
        }
        oBase64.innerHTML = "请选择图片文件!";
        $('#img_src').val("");
        oPreview.src = "../img/up_img.jpg";
    } else {
        oBase64.innerHTML = "您当前使用的浏览器不支持读取文件功能";
    }
}

function userid() {
    var user = $.cookie('user');
    if (user == null) {
        document.getElementById('username').value = "";
        document.getElementById('password').value = "";
        $('#login').modal('show');
    }
}

function userup() {
    var user = $.cookie('user');
    if (user != null) {
        $.removeCookie('user');
        $("#userid").html("游客|登录");
        $("#userup").html("注册");
        window.location.reload()
    } else {
        document.getElementById('usernamet').value = "";
        document.getElementById('passwordt').value = "";
        document.getElementById('wen').value = "";
        $('#register').modal('show')
    }
}

function login() {
    var usernames = document.getElementById('username').value;
    var passwords = document.getElementById('password').value;
    if (usernames.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，账号内容不能为空！", {
            title: "发现错误",
            icon: 5
        });
        username.focus();
        return
    } else if (passwords.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，密码内容不能为空！", {
            title: "发现错误",
            icon: 5
        });
        password.focus();
        return
    } else {
        $.post("./api/login.php", {
            username: usernames,
            password: passwords
        }, function(datalogin, status) {
            objlogin = JSON.parse(datalogin);
            if (objlogin.status == "YES") {
                layer.alert(objlogin.message);
                $('#login').modal('toggle');
                $("#userup").html("登出");
                $("#userid").html(usernames);
                $.cookie('user', usernames);
                document.getElementById("modbut").style.display = "inline";
                getmod()
            } else {
                layer.alert(objlogin.message, {
                    title: "登录失败",
                    icon: 5
                })
            }
        })
    }
}

function register() {
    var usernamest = document.getElementById('usernamet').value;
    var passwordst = document.getElementById('passwordt').value;
    var wens = document.getElementById('wen').value;
    if (usernamest.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，账号内容不能为空！", {
            title: "发现错误",
            icon: 5
        });
        usernamet.focus();
        return
    } else if (passwordst.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，密码内容不能为空！", {
            title: "发现错误",
            icon: 5
        });
        passwordt.focus();
        return
    } else if (wens.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，验证口令不能为空！", {
            title: "发现错误",
            icon: 5
        });
        wen.focus();
        return
    } else {
        $.post("./api/register.php", {
            username: usernamest,
            password: passwordst,
            wen: wens
        }, function(register, status) {
            objregister = JSON.parse(register);
            if (objregister.status == "YES") {
                layer.alert(objregister.message);
                $('#register').modal('toggle');
                $("#userup").html("登出");
                $("#userid").html(usernamest);
                $.cookie('user', usernamest);
                document.getElementById("modbut").style.display = "inline";
                getmod()
            } else {
                layer.alert(objregister.message, {
                    title: "注册失败",
                    icon: 5
                })
            }
        })
    }
}

function zhmm() {
    var usid = document.getElementById('usid').value;
    var usmm = document.getElementById('usmm').value;
    var went = document.getElementById('went').value;
    if (usid.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，账号内容不能为空！", {
            title: "发现错误",
            icon: 5
        });
        usid.focus();
        return
    } else if (usmm.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，密码内容不能为空！", {
            title: "发现错误",
            icon: 5
        });
        usmm.focus();
        return
    } else if (went.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，验证口令不能为空！", {
            title: "发现错误",
            icon: 5
        });
        went.focus();
        return
    } else {
        $.post("./api/zhmm.php", {
            username: usid,
            password: usmm,
            wen: went
        }, function(register, status) {
            objregister = JSON.parse(register);
            if (objregister.status == "YES") {
                layer.alert(objregister.message);
                $('#usermm').modal('toggle');
                $("#userup").html("登出");
                $("#userid").html(usid);
                $.cookie('user', usid);
                document.getElementById("modbut").style.display = "inline";
                getmod()
            } else {
                layer.alert(objregister.message, {
                    title: "找回&修改密码失败",
                    icon: 5
                })
            }
        })
    }
}

function getmod() {
    var user = $.cookie('user');
    $.post("./api/getmod.php", {
        user: user
    }, function(getmod, status) {
        getmods = JSON.parse(getmod);
        if (getmods.status == "YES") {
            $('#moddiv').html('');
            for (var i = 0; i < getmods.mod.length; i++) {
				var team = $('<div class="col-md-4"style="text-align:center;margin-top:5vh;position:relative; height:240px;"onmouseover=\'$("#mbid' + i + '").show();\'onmouseout=\'$("#mbid' + i + '").hide();\'></div>');
                team.append('<img src="' + getmods.mod[i].modimg + '" alt="此模板无预览" style="width:100%; height:auto; max-height: 220px; min-height: 220px;" class="img-thumbnail"><span>' + getmods.mod[i].modname + '</span><p class="text-danger">' + getmods.mod[i].customWidth + ' mm * ' + getmods.mod[i].customHeight + ' mm</p><div id="mbid' + i + '"style="display:none; position:absolute; left: 18%; top: 77%;"><button type="button"class="btn btn-danger btn-xs"onclick="get_old(\'' + getmods.mod[i].modid + '\',\'' + getmods.mod[i].modname + '\');">删除</button><button type="button" class="btn btn-warning btn-xs" style="margin-left: 0.38vw;" onclick="up_mods(\'' + getmods.mod[i].modid + '\',\'' + getmods.mod[i].modname + '\');">更新</button><button type="button"class="btn btn-success btn-xs"style="margin-left: 0.38vw;"onclick="getjson(' + getmods.mod[i].modid + ');">载入</button></div>');
                $('#moddiv').append(team)
            }
        } else {
            $("#moddiv").html('<button type="button" class="btn btn-default">您还没有添加模板呢亲</button>')
        }
    })
}

function getjson(modid) {//读取模板信息
	var modid = modid.toString();
    if (modid.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，模板名称内容不能为空！", {
            title: "发现错误",
            icon: 5
        });
        return
    } else {
        var user = $.cookie('user');
        $.post("./api/getjson.php", {
            user: user,
            modid: modid
        }, function(getjson, status) {
            getjsons = JSON.parse(getjson);
            if (getjsons.status == "YES") {
                $('#hiprint-printTemplate').html('');
                hiprintTemplate = new hiprint.PrintTemplate({
                    template: JSON.parse(getjsons.modjson),
                    settingContainer: '#PrintElementOptionSetting'
                });
                getjson_s = JSON.parse(getjsons.modjson);
                //console.log(getjson_s.panels[0]);
                $("#customHeight").val(getjson_s.panels[0].height);
                $("#customWidth").val(getjson_s.panels[0].width);
                $("#customHeight_t").html("高度 : [ "+getjson_s.panels[0].height+" ] mm");
                $("#customWidth_t").html("高度 : [ "+getjson_s.panels[0].width+" ] mm");
                hiprintTemplate.design('#hiprint-printTemplate');
                $('#moddivs').modal('toggle');
				get_img();
            } else {
                layer.alert(getjsons.message, {
                    title: "载入失败",
                    icon: 5
                });
                $('#moddivs').modal('toggle')
            }
        })
    }
}

function up_mod() {//上传模板
	get_img();
	getJsonTid();
	setTimeout(function(){
	    layer.prompt({title: '请输入模板名称!'}, function(modname, index){
    		layer.closeAll(); //疯狂模式，关闭所有层
    		var modimg = document.getElementById('modimg').value;
    		var modstr = document.getElementById('textarea').value;
    		var timestamp = Date.parse(new Date()); 
    		
    		if (modname.replace(/(^\s*)|(\s*$)/g, "") == "") {
    			layer.alert("请注意，模板名称内容不能为空！", {
    				title: "发现错误",
    				icon: 5
    			});
    			return
    		} else if (modimg.replace(/(^\s*)|(\s*$)/g, "") == "") {
    			layer.alert("读取模板预览出错，请稍后重试！", {
    				title: "发现错误",
    				icon: 5
    			});
    			return
    		} else if (modstr.replace(/(^\s*)|(\s*$)/g, "") == "") {
    			layer.alert("读取模板信息出错，请稍后重试！", {
    				title: "发现错误",
    				icon: 5
    			});
    			return
    		} else {
    			layer.msg('你确定保存此模板到云端吗？', {
    				time: 0,
    				btn: ['保存|确认', '取消|返回'],
    				yes: function(index) {
    					layer.closeAll(); //疯狂模式，关闭所有层
    					var user = $.cookie('user');
    					$.post("./api/upmod.php", {
    						user: user,
    						modid: timestamp,
    						modname: modname,
    						modimg: $("#modimg").val(),
    						modjson: $("#textarea").val(),
    						customWidth:$("#customWidth").val(),
    						customHeight:$("#customHeight").val()
    					}, function(getup, status) {
    						getup = JSON.parse(getup);
    						if (getup.status == "YES") {
    							layer.alert(getup.message);
    							getmod();
    							$('#moddivs').modal('toggle')
    						} else {
    							layer.alert(getup.message, {
    								title: "保存模板失败",
    								icon: 5
    							})
    						}
    					})
    				}
    			})
    		}
    	});
	},1000);
}

function up_mods(modid,modname) {//更新模板
	get_img();
	getJsonTid();
	setTimeout(function(){
    	var modimg = document.getElementById('modimg').value;
    	var modstr = document.getElementById('textarea').value;
    	
    	if (modid.replace(/(^\s*)|(\s*$)/g, "") == "") {
    		layer.alert("读取模板信息出错，请稍后重试！", {
    			title: "发现错误",
    			icon: 5
    		});
    		return
    	} else if (modname.replace(/(^\s*)|(\s*$)/g, "") == "") {
    		layer.alert("读取模板名称出错，请稍后重试！", {
    			title: "发现错误",
    			icon: 5
    		});
    		return
    	} else if (modimg.replace(/(^\s*)|(\s*$)/g, "") == "") {
    		layer.alert("读取模板预览出错，请稍后重试！", {
    			title: "发现错误",
    			icon: 5
    		});
    		return
    	} else if (modstr.replace(/(^\s*)|(\s*$)/g, "") == "") {
    		layer.alert("读取模板信息出错，请稍后重试！", {
    			title: "发现错误",
    			icon: 5
    		});
    		return
    	} else {
    		layer.msg('你确定更新此模板['+ modname +']到云端吗？', {
    			time: 0,
    			btn: ['更新|确认', '取消|返回'],
    			yes: function(index) {
    				layer.closeAll(); //疯狂模式，关闭所有层
    				var user = $.cookie('user');
    				$.post("./api/upmods.php", {
    					user: user,
    					modid: modid,
    					modname: modname,
    					modimg: $("#modimg").val(),
    					modjson: $("#textarea").val(),
    					customWidth:$("#customWidth").val(),
    					customHeight:$("#customHeight").val()
    				}, function(getup, status) {
    					getup = JSON.parse(getup);
    					if (getup.status == "YES") {
    						layer.alert(getup.message);
    						getmod();
    						$('#moddivs').modal('toggle');
    					} else {
    						layer.alert(getup.message, {
    							title: "更新模板失败",
    							icon: 5
    						})
    					}
    				})
    			}
    		})
    	}
	},1000);
}

function get_old(modid,modname) {//删除模板
    if (modid.replace(/(^\s*)|(\s*$)/g, "") == "") {
        layer.alert("请注意，模板名称内容不能为空！", {
            title: "发现错误",
            icon: 5
        });
        return
    } else {
        layer.msg('你确定删除【'+modname+'】此模板吗？', {
            time: 0,
            btn: ['我意已决', '留它一命'],
            yes: function(index) {
                layer.closeAll(); //疯狂模式，关闭所有层
                var user = $.cookie('user');
                $.post("./api/getold.php", {
                    user: user,
                    modid: modid
                }, function(old, status) {
                    old = JSON.parse(old);
                    if (old.status == "YES") {
                        layer.alert(old.message);
                        getmod();
                        $('#moddivs').modal('toggle')
                    } else {
                        layer.alert(old.message, {
                            title: "删除模板失败",
                            icon: 5
                        })
                    }
                })
            }
        })
    }
}

function get_img(){
	html2canvas(document.querySelector(".hiprint-printPaper")).then(canvas => {
		var imgUrl = canvas.toDataURL("image/jpeg", 0.1);//转化base64编码数据
		console.log(imgUrl);
		$("#modimg").val(imgUrl);
	});
}

//点击放大或者缩小
function amplify(index){//index决定放大或者缩小1是放大2是缩小
    var index=index;
    
    if(index==1){
        if (parseInt($("#bfb").html()) >= 100) {
            var cshbfb = parseInt($("#bfb").html()) + 50;
        }else{
            var cshbfb = parseInt($("#bfb").html()) + 10;
        }
        if(cshbfb > 300){
            layer.msg("已经超出设定最大值了亲");
        }else{
            if(cshbfb > 150){layer.msg("设计面板放大后对拖动会产生影响，建议您使用键盘方向键进行移动调整");}
            var obj = document.getElementById("hiprint-printTemplate");
            obj.style.cssText = "transform-origin:top left;"
            $("#bfb").html(cshbfb + "%");
            var biger = parseFloat(cshbfb/100);
            $("#hiprint-printTemplate").css({"transform":"scale("+biger+")"});
            if(cshbfb < 150){
                $("#div").css({"padding-top":"0.1vw","padding-left":"0.1vw","margin-top":"0.1vw","margin-left":"0.1vw"});
                $("#hiprint-printTemplate").css({"padding-top":"0.1vw","padding-left":"0.1vw","margin-top":"0.1vw","margin-left":"0.1vw"});
            }else{
                $("#div").css({"padding-top":"0.2vw","padding-left":"0.2vw","margin-top":"0.2vw","margin-left":"0.2vw"});
                $("#hiprint-printTemplate").css({"padding-top":"0.5vw","padding-left":"0.5vw","margin-top":"0.5vw","margin-left":"0.5vw"});
            }
        }
        
    }else if(index==2){
        if (parseInt($("#bfb").html()) <= 100) {
            var cshbfb = parseInt($("#bfb").html()) - 10;
        }else{
            var cshbfb = parseInt($("#bfb").html()) - 50;
        }
        
        if(cshbfb < 50){
            layer.msg("已经超出设定最小值了亲");
        }else{
            var obj = document.getElementById("hiprint-printTemplate");
            obj.style.cssText = "transform-origin:top left;"
            $("#bfb").html(cshbfb + "%");
            var biger = parseFloat(cshbfb/100);
            $("#hiprint-printTemplate").css({"transform":"scale("+biger+")"});
            if(cshbfb < 150){
                $("#div").css({"padding-top":"0.1vw","padding-left":"0.1vw","margin-top":"0.1vw","margin-left":"0.1vw"});
                $("#hiprint-printTemplate").css({"padding-top":"0.1vw","padding-left":"0.1vw","margin-top":"0.1vw","margin-left":"0.1vw"});
            }else{
                $("#div").css({"padding-top":"0.2vw","padding-left":"0.2vw","margin-top":"0.2vw","margin-left":"0.2vw"});
                $("#hiprint-printTemplate").css({"padding-top":"0.5vw","padding-left":"0.5vw","margin-top":"0.5vw","margin-left":"0.5vw"});
            }
        }
    }
}
$("#bfb").click(function(){//点击按钮恢复原始大小
    var obj = document.getElementById("hiprint-printTemplate");
    obj.style.cssText = "transform-origin:top left;"
    $("#bfb").html(100 + "%");
    $("#hiprint-printTemplate").css({"transform":"scale(1)"});
});
$("#div").dblclick(function(){//双击页面恢复原始大小
    var obj = document.getElementById("hiprint-printTemplate");
    obj.style.cssText = "transform-origin:top left;"
    $("#bfb").html(100 + "%");
    $("#hiprint-printTemplate").css({"transform":"scale(1)"});
});
$("#bslist").click(function(){
    layer.msg("双击常用标识按钮可关闭标识控件模块");
    $("#bsdiv").show();
    $("#txdiv").hide();
    $("#szdiv").hide();
    $("#nrdiv").hide();
});
$("#gbbsbtn").click(function(){
    $("#bsdiv").hide();
    $("#nrdiv").show();
    $("#txdiv").show();
    $("#szdiv").show();
});
//上传表格转JSON
function importf(obj) {
    if (!obj.files) {
        $('#plyr').hide();
        return
    }
    var f = obj.files[0];
    var reader = new FileReader();
    reader.onload = function(e) {
        var data = e.target.result;
        wb = XLSX.read(data, {
            type: 'binary'
        });
        var printDatast = JSON.stringify(XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]));

		//console.log(printDatast);
		//console.log(JSON.parse(printDatast));
		
		var printDatast_gg = JSON.parse(printDatast);
		printDatast_gg[0]['table_printDatast'] = JSON.parse(printDatast);
		
		console.log(JSON.stringify(printDatast_gg));
		console.log(printDatast_gg);
		
        document.getElementById("printDatas").value = JSON.stringify(printDatast_gg);
        $('#plyr').show();
    };
    reader.readAsBinaryString(f);
}

function fix(data) {
    var o = "",
        l = 0,
        w = 10240;
    for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
    o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
    return o
}
//上载表格转JSON结束
/*
document.onkeydown = function() {
    var e = window.event || arguments[0];
    if (e.keyCode == 123) {
        return false
    }
}
document.oncontextmenu = function() {
    return false
}
document.onkeydown = function() {
    if ((e.ctrlKey) && (e.keyCode == 83)) {
        return false
    }
}
document.onkeydown = function() {
    var e = window.event || arguments[0];
    if (e.keyCode == 123) {
        return false
    } else if ((e.ctrlKey) && (e.shiftKey) && (e.keyCode == 73)) {
        return false
    } else if ((e.shiftKey) && (e.keyCode == 121)) {
        return false
    }
};*/

function say() {
    layer.open({
        type: 1,
        shade: false,
        title: "吐槽反馈&功能建议",
        content: ('<strong>添加QQ:<br><div style="width: 100%;text-align: center;">2394828839</div></strong><br><br>并备注：<br><strong><ins><div style="width: 100%;text-align: center;">标签设计打印用户</div></ins></strong> <br><br> 感谢您的支持与鼓励,让我们变得更好!')
    })
}